package com.github.shuaidd.service.mapper;

import org.activiti.engine.ManagementService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;

/**
 * 描述 mapper 抽象类
 *
 * @author ddshuai
 * @date 2020-07-20 21:02
 **/
public abstract class BaseMapperService {

    @Autowired
    protected ManagementService managementService;

    public String getOrderByFormat(Sort sort){
        final String[] format = {""};
        if (sort != null){
            sort.forEach(order -> {
                if (StringUtils.isEmpty(format[0])){
                    format[0] = order.getProperty() + " " + order.getDirection().name();
                } else {
                    format[0] = format[0] +","+ order.getProperty() + " " + order.getDirection().name();
                }
            });
        }
        return format[0];
    }
}
